#ifndef BMA180_
#define BMA180_

#include "common.h"


#ifdef __cplusplus
extern "C"
{
#endif

//Definition of BMA180 Register
#define BMA180_ADDR 0x40
#define BMA180_ID 0x00
#define BMA180_Version 0x01
#define BMA180_ACCXLSB 0x02
#define BMA180_ACCXMSB 0x03
#define BMA180_ACCYLSB 0x04
#define BMA180_ACCYMSB 0x05
#define BMA180_ACCZLSB 0x06
#define BMA180_ACCZMSB 0x07
#define BMA180_TEMPERATURE 0x08
#define BMA180_STATREG1 0x09
#define BMA180_STATREG2 0x0A
#define BMA180_STATREG3 0x0B
#define BMA180_STATREG4 0x0C
#define BMA180_CTRLREG0 0x0D
#define BMA180_CTRLREG1 0x0E
#define BMA180_CTRLREG2 0x0F
#define BMA180_SOFTRST	0x10

#define BMA180_BWTCS	0x20
#define BMA180_CTRLREG3 0x21
#define BMA180_CTRLREG4 0x22
#define BMA180_HY		0x23
#define BMA180_SLPTAP 	0x24	//slope_tapsens_info
#define BMA180_HIGHLOW  0x25	//high_low_info
#define BMA180_LOWDUR 	0x26
#define BMA180_HIGHDUR 	0x27
#define BMA180_TAPSENS	0x28
#define BMA180_LOWTH 	0x29
#define BMA180_HIGHTH 	0x2A
#define BMA180_SLOPETH 	0x2B
#define BMA180_CD1 		0x2C	//customer data
#define BMA180_CD2 		0x2D	//customer data
#define BMA180_TCOX 	0x2E
#define BMA180_TCOY 	0x2F
#define BMA180_TCOZ 	0x30
#define BMA180_GAINT 	0x31
#define BMA180_GAINX 	0x32
#define BMA180_GAINY 	0x33
#define BMA180_GAINZ 	0x34
#define BMA180_OFTLSB1 	0x35
#define BMA180_OFTLSB2 	0x36
#define BMA180_OFFSETT 	0x37
#define BMA180_OFFSETX 	0x38
#define BMA180_OFFSETY 	0x39
#define BMA180_OFFSETZ 	0x3A
#define BMA180_CRC	 	0x3B

#define BMA180_1G		0x00	//three bits
#define BMA180_1_5G		0x01
#define BMA180_2G		0x02
#define BMA180_3G		0x03
#define BMA180_4G		0x04
#define BMA180_8G		0x05
#define BMA180_16G		0x06

#define BMA180_10HZ		0x00	//four bits
#define BMA180_20HZ		0x01
#define BMA180_40HZ		0x02
#define BMA180_75HZ		0x03
#define BMA180_150HZ	0x04
#define BMA180_300HZ	0x05
#define BMA180_600HZ	0x06
#define BMA180_1200HZ	0x07
#define BMA180_1HZ_HP	0x08
#define BMA180_BANDPASS	0x09

#define BMA180_LOWNOISE	0x00	//two bits
#define BMA180_LOWPOWER	0x11

#define BMA180_RESET_VAL 0xB6


int BMA180_CONNECT(GIO_Handle inhd,GIO_Handle outhd);	//Connect to BMA180, read ID and identify
int BMA180_READ_REG(GIO_Handle inhd,GIO_Handle outhd, Uint8 REG, Uint8 *buf, size_t len);
int BMA180_WRITE_REG(GIO_Handle inhd,GIO_Handle outhd, Uint8 REG,Uint8 value, op_mode op);
int BMA180_SET_RANGE(GIO_Handle inhd,GIO_Handle outhd, Uint8 range);
int BMA180_SET_BW(GIO_Handle inhd,GIO_Handle outhd, Uint8 bandwith);
int BMA180_SOFTRESET(GIO_Handle inhd,GIO_Handle outhd);
int BMA180_LOCK(GIO_Handle inhd,GIO_Handle outhd);
int BMA180_UNLOCK(GIO_Handle inhd,GIO_Handle outhd);
void BMA180_SCALE_DATA(short*rdata, double *data,int acc_scale);
int BMA180_GET_RDATA(GIO_Handle inhd,GIO_Handle outhd,short *data);
double BMA180_GETROLL(double x,double y,double z);
double BMA180_GETPITCH(double x,double y,double z);
void BMA180_CAL_DATA(short*rdata, double *data, int acc_scale, Uint8 mode);	//rdata-raw data, data-output 3*1, acc_scale, mode

#ifdef __cplusplus
}
#endif /* extern "C" */


#endif
